<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-09-06
 * Time: 17:57
 */

namespace App\Http\Controllers\Backstage;


use App\Model\Backstage\Log;
use App\Tool\Error;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class LogController extends Controller
{
    //操作日志的列表
    public function logList(Request $request)
    {
        $param = $request->all();
        //日志操作类型（1登录    2退出登录   3新增房源   4.修改房源   5. 删除房源
        //  6.新增客源  7.修改客源   8.删除客源    9.楼盘字典    10.员工   11. 合同    12.部门）
        if(!$request->input('l_type')){
            return $this->error(Error::PARAM_MISSING);
        }
        $where[] = ['l_type', $request->input('l_type')];
        //开始时间
        if ($request->input('start_time')) {
            $where[] = ['l_create_time', '>=', strtotime($param['start_time'].' 00:00:00')];
        } else {
            $where[] = ['l_create_time', '>=', strtotime(date('Y-m-d',strtotime('-1 month')).' 00:00:00')];
        }
        //结束时间
        if ($request->input('end_time')) {
            $where[] = ['l_create_time', '<=', strtotime($param['end_time'].' 23:59:59')];
        } else {
            $where[] = ['l_create_time', '<=', time()];
        }
        //部门id
        if ($request->input('u_d_id')) {
            $where[] = ['l_b_id', $request->input('u_d_id')];
        }
        //员工ID
        if ($request->input('u_id')) {
            $where[] = ['l_u_id', $request->input('u_id')];
        }
        $log = new Log();
        $list = $log->loglist($where, env('PAGE_LIMIT_ADMIN'));
        if (!$list) {
            $data['start'] = date('Y-m-d',strtotime('-1 month'));
            $data['end']  = date('Y-m-d',time());
            return $this->error(Error::NULL_DATA,$data);
        }
        $start = date('Y-m-d',strtotime('-1 month'));
        $end = date('Y-m-d',time());
        return $this->success('ok', $list, $start, $end);
    }

}